// 20 pts
#include<bits/stdc++.h>
using namespace std;
const int MAXN=200005;
int a[MAXN],n;

int calc(int color){
    int ans=0;
    bool col[20]={0};
    for(int i=n-1;i>=0;i--)
        col[n-i]=(bool)(color&(1<<i));
    int idx[2]={-1,-1};
    for(int i=1;i<=n;i++){
        if(idx[col[i]]!=-1){
            ans+=(a[idx[col[i]]]==a[i])*a[i];
        }
        idx[col[i]]=i;
    }
    return ans;
}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        if(n<=15){
            int maxans=-1;
            // make color queue
            for(int i=0;i<pow(2,n-1);i++){
                maxans=max(maxans,calc(i));
            }
            cout<<maxans<<endl;
        }
        for(int i=1;i<=n;i++) a[i]=0;
    }

    return 0;
}